package com.apex.shared.starter.exception;

import com.apex.shared.starter.constant.HttpStatusCode;
import lombok.Getter;

import java.io.Serial;

/**
 * 业务异常
 *
 * @author MoNaiHui
 */
@Getter
public class ServiceException extends RuntimeException {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private final Integer code;

    /**
     * 错误提示
     */
    private final String message;

    /**
     * 空构造方法，默认状态码为500
     */
    public ServiceException() {
        this(HttpStatusCode.INTERNAL_SERVER_ERROR);
    }

    public ServiceException(String message) {
        this(HttpStatusCode.INTERNAL_SERVER_ERROR.getValue(), message);
    }

    public ServiceException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public ServiceException(HttpStatusCode httpStatusCode) {
        this(httpStatusCode.getValue(), httpStatusCode.getReasonPhrase());
    }

    public ServiceException(HttpStatusCode httpStatusCode, String message) {
        this(httpStatusCode.getValue(), message);
    }
} 